package chap04.Brackets;

import chap04.Brackets.StackC;

/**
 * Created by root on 2017/6/30.
 */
class BracketChecker{
    public String input;

    public BracketChecker(String input) {
        this.input = input;
    }

    public boolean check() {
        int stackSize = input.length();
        StackC stackC = new StackC(stackSize);
        for (int i=0; i<stackSize; i++) {
            char ch = input.charAt(i);
            char cPop;
            switch (ch) {
                case '{' :
                case '[' :
                case '(' : stackC.push(ch);
                            break;
                case '}' :
                case ']' :
                case ')' :
                    if (!stackC.isEmpty()) {
                        char chx = stackC.pop();
                        if ((ch == '}'&&chx!='{')||
                                (ch == ']'&&chx!='[')||
                                (ch == ')'&&chx!='(')) {
                            return false;
                        }
                    } else {
                        return false;
                    }
                    break;
            }

        }
        if (!stackC.isEmpty()) {
            return false;
        }
        return true;
    }

}
public class BracketsApp {
    public static void main(String[] args) {
        String input = "a{b(c[d]e)f}";
        BracketChecker bracketChecker = new BracketChecker(input);
        System.out.println(bracketChecker.check());
    }
}
